home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / Adroff2 / Diagrammer.m < prev    next >
Encoding:
Text File  |  1991-10-14  |  9.9 KB  |  448 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "Diagrammer.h"
  5.  
  6. @implementation Diagrammer
  7.  
  8.     
  9.     //  Modified for NeXT by J. Rettenmayer   5/16/91
  10. /*
  11. $Header: c:/res/adroff/RCS/adroff.c 1.9 88/09/07 07:56:03 jr Exp $
  12. */
  13.  
  14. /* Idea for action diagram formatter originated by John W. Rettenmayer,
  15.    who has guided the design and also contributed some code.
  16.  
  17.    Spring Quarter '86 --  ACTION DIAGRAMMER first programmed by Joyce Miller,
  18.                           Rhonda Aubrey, and Rob Romsa at
  19.               Eastern Montana College
  20.  
  21.    Spring Quarter '87 -- Line wrap and line continuation features added
  22.                  by Don Joppa at Eastern Montana College
  23.  
  24.    Summer 1988 --------  Bugs fixed and graphics characters added by Darin
  25.                          LeBleu at Northeast Louisiana University
  26. */
  27.  
  28. #include <stdio.h>
  29. #include <math.h>
  30. #include <ctype.h>
  31.  
  32. #define EQ ==
  33.  
  34. #define DOUHORG 205
  35. #define DOULOWCORG 200
  36. #define DOUUPPCORG 201
  37. #define DOUVERG 186
  38. #define EQUALA 61
  39. #define FALSE 0
  40. #define INDENT 5
  41. #define LNLGTH 512
  42. #define NSIZE 15
  43. #define PLUS 43
  44. #define PRINTLNLGTH 80
  45. #define RIGHT_MARGIN 7
  46. #define SINHORG 196
  47. #define SINLOWCORG 192
  48. #define SINLOWLEFCOR 192
  49. #define SINLOWRIGCOR 217
  50. #define SINUPPCORG 218
  51. #define SINUPPRIGCOR 191
  52. #define SINVERA 124
  53. #define SINVERCONA 124
  54. #define SINVERCONG 195
  55. #define SINVERG 179
  56. #define SLASHA 45
  57. #define ARROW 60
  58. #define TRUE 1
  59.  
  60. - formatDiagram:sender
  61. {
  62.  
  63. int     firstcol = 10;
  64. int     indwidth = 5;
  65. int     scrwidth = 80;
  66.  
  67.     NXStream *inStream;
  68.     NXStream *outStream;
  69.  
  70.    const char *inFileName = "tmpAdroffSource";
  71.     const char *outFileName = "tmpAdroffDiagram";
  72.  
  73. //FILE * infile;
  74. //FILE * outfile;
  75. //main (argc, argv)
  76. //int     argc;
  77. //char   *argv[];
  78.  
  79.     int     i,
  80.         test,
  81.             numbars = 0,
  82.             g,
  83.             barchar = 0,
  84.         fl = 'm';
  85.     char    line[LNLGTH];
  86.  
  87.     //g = openfiles (argc, argv);
  88.     
  89.     inStream = NXMapFile(inFileName, NX_READONLY);       
  90.     NXSeek(inStream,0, NX_FROMSTART);  
  91.     outStream = NXMapFile(outFileName, NX_WRITEONLY);       
  92.     NXSeek(stream,0, NX_FROMSTART);  
  93.     
  94.     while (getstring (line) !=  0) {
  95.     test = FALSE;
  96.     if (line[0] EQ '.') {
  97.         test = TRUE;
  98.         execute (line, &numbars, g);
  99.         if (line[1] != 'b' && line[1] != 'i' && line[1] != 'g') {
  100.         getstring (line);
  101.         if (line[0] EQ '.' && line[1] EQ 'b')
  102.           drawbox (numbars, g);
  103.         else
  104.           print_line (line, numbars, test);
  105.         }
  106.     }
  107.     else {
  108.         printbars (numbars, barchar, fl);
  109.         for (i = 0; i < indwidth; i++)
  110.         fprintf (outfile, " ");
  111.         print_line (line, numbars, test);
  112.     }
  113.     }
  114.  
  115.     NXFlush(outStream);
  116.     NXSaveToFile(outStream,outFileName);
  117.     NXCloseMemory(outStream,NX_FREEBUFFER);
  118.     NXCloseMemory(inStream,NX_FREEBUFFER);
  119. }
  120.  
  121.  
  122. execute (line, numbars, g)
  123. char   *line;
  124. int    *numbars;
  125. int    g;
  126.  
  127. {
  128.  
  129.     char    command,
  130.             ext,
  131.             fl = 'e';
  132.     int        barchar,
  133.             n;
  134.     static  int     sv = SINVERA,
  135.             svc = SINVERCONA,
  136.             dvr = SINVERA,
  137.             shr = SINVERA,
  138.             dhl = SINVERA,
  139.             shl = SINVERA,
  140.             dhr = SINVERA,
  141.                  sh = SLASHA,
  142.             dh = SLASHA,
  143.                  dhh = EQUALA;
  144.     if (g == 1) sv = SINVERG,
  145.         svc = SINVERCONG,
  146.         dvr = DOUVERG,
  147.         shr = SINUPPCORG,
  148.         dhl = DOULOWCORG,
  149.         shl = SINLOWCORG,
  150.         dhr = DOUUPPCORG,
  151.         sh = SINHORG,
  152.         dh = DOUHORG,
  153.         dhh = DOUHORG;
  154.  
  155.  
  156.     ext = (strlen (line) > 2) ? line[2] : '1';
  157.     command = line[1];
  158.     barchar = 0;
  159.  
  160.    switch (command) {
  161.     case 'i':
  162.         barchar = sv;
  163.         inoutput (*numbars, barchar, fl, ext);
  164.         break;
  165.     case 'b':
  166.         barchar = sv;
  167.         printbars (*numbars, barchar, fl);
  168.         drawbox (*numbars, g);
  169.         break;
  170.     case 't':
  171.         printarrows (*numbars, ext, g);
  172.         break;
  173.     case 'p':
  174.         fprintf (outfile, "\f\n");
  175.         barchar = sv;
  176.         printbars (*numbars, barchar, fl);
  177.         break;
  178.     case 's':                   /* selection command         */
  179.     case 'c':                   /* original "choice" command */
  180.         barchar = sv;
  181.         printbars (*numbars, barchar, fl);
  182.         fprintf (outfile, "%c%c%c%c%c", shr, sh, sh, sh, ' ');
  183.         (*numbars)++;
  184.         break;
  185.  
  186.     case '-':
  187.          barchar = sv;
  188.         printbars (*numbars - 1, barchar, fl);
  189.             fprintf (outfile, "%c%c%c%c%c", svc, sh, sh, sh, ' ');
  190.         break;
  191.  
  192.     case 'e':
  193.         (*numbars)--;
  194.         n = printbars (*numbars);
  195.         if (n == 186)
  196.         fprintf (outfile, "%c%c%c%c%c", dhl, dh, dh, dh, ' ');
  197.         else
  198.         fprintf (outfile, "%c%c%c%c%c", shl, sh, sh, sh, ' ');
  199.         break;
  200.  
  201.     case 'r':
  202.         barchar = dvr;
  203.         printbars (*numbars, barchar, fl);
  204.         fprintf (outfile, "%c%c%c%c%c", dhr, dhh, dhh, dhh, ' ');
  205.         (*numbars)++;
  206.         break;
  207.     default:
  208.         fprintf (stderr, "UNRECOGNIZABLE DOT COMMAND -- %c --\n\n", command)
  209. ;
  210.         fprintf (stderr, "PLEASE CORRECT DOT COMMAND\n");
  211.         exit (1);
  212.         break;
  213.     }
  214. }
  215.  
  216.  
  217. drawbox (numbars, g)
  218. int    *numbars,
  219.        g;
  220. {
  221.  
  222.     char    line[LNLGTH];
  223.     int     i,
  224.         fl = 'b',
  225.         barchar = 0,
  226.             dc1 = PLUS,
  227.         dc2 = PLUS,
  228.         dc3 = PLUS,
  229.         dc4 = PLUS,
  230.         s = SLASHA,
  231.         l = SINVERA;
  232.  
  233.     if (g == 1)
  234.         dc1 = SINUPPCORG,
  235.         dc2 = SINUPPRIGCOR,
  236.         dc3 = SINLOWLEFCOR,
  237.         dc4 = SINLOWRIGCOR,
  238.         s =   SINHORG,
  239.         l =   SINVERG;
  240.     getstring (line);
  241.     if (line[strlen (line) - 1] EQ '\n')
  242.     line[strlen (line) - 1] = '\0';
  243.     fprintf (outfile, "     %c", dc1);
  244.     for (i = 0; i < (strlen (line) + 2); i++)
  245.     fprintf (outfile, "%c", s);
  246.     fprintf (outfile, "%c\n", dc2);
  247.     printbars (numbars, barchar, fl);
  248.     fprintf (outfile, "     %c ", l);
  249.     fprintf (outfile, "%s", line);
  250.     fprintf (outfile, " %c\n", l);
  251.     printbars (numbars);
  252.     fprintf (outfile, "     %c", dc3);
  253.     for (i = 0; i < (strlen (line) + 2); i++)
  254.     fprintf (outfile, "%c", s);
  255.     fprintf (outfile, "%c\n", dc4);
  256. }
  257.  
  258.  
  259. inoutput (numbars, barchar, fl, ext)
  260. int     numbars;
  261. int     barchar;
  262. char    fl;
  263. char    ext;
  264. {
  265.     char    line[LNLGTH];
  266.     int     i, j,
  267.             fill;
  268.     int     extension;
  269.  
  270.     extension = ext - '0';
  271.  
  272.     for (i = 0; i < extension; i++) {
  273.     printbars (numbars, barchar, fl);
  274.     getstring (line);
  275.     fill = scrwidth - ((2 * (indwidth * numbars)) + strlen (line) + 5);
  276.     for (j = 0; j < fill; j++) {
  277.         fprintf (outfile, " ");
  278.     }
  279.     fprintf (outfile, "*%s", line);
  280.     }
  281. }
  282.  
  283.  
  284. printarrows (numbars, ext, g)
  285. int     numbars;
  286. char    ext;
  287. int g;
  288. {
  289.     int     i, num, extension;
  290.     int numext,
  291.     fl = 'a',
  292.         barchar = 0,
  293.         s = SLASHA,
  294.     ar = ARROW;
  295.  
  296.     if (g == 1)
  297.         s = SINHORG,
  298.         ar = ARROW;
  299.  
  300.     extension = ext - '0';
  301.  
  302.     if (extension == numbars) {
  303.     for (i = 1; i < (firstcol); i++)
  304.         fprintf (outfile, " ");
  305.     }
  306.     else {
  307.     numext = (numbars - extension);
  308.     printbars (numext, barchar, fl);
  309.     }
  310.     fprintf (outfile, "\b%c", ar);
  311.     for (i = 0; i < extension; i++)
  312.     fprintf (outfile, "%c%c%c%c%c", s, s, s, s, s);
  313.     fprintf (outfile, "%c%c%c%c ", s, s, s, s);
  314. }
  315.  
  316.  
  317. printbars (numbars, barchar, fl)
  318. int     numbars;
  319. int     barchar;
  320. char    fl;
  321. {
  322. static    int    bartable[NSIZE];
  323.     int     i,
  324.             j,
  325.         x;
  326.     bartable[0] = 179;
  327.     if (fl == 'e') bartable[numbars + 1] = barchar;
  328.     for (i = 1; i < firstcol; i++)
  329.     fprintf (outfile, " ");
  330.     for (i = 1; i <= numbars; i++) {
  331.     fprintf (outfile, "%c", bartable[i]);
  332.     for (j = 1; j < indwidth; j++)
  333.         fprintf (outfile, " ");
  334.     }
  335.     return(bartable[i]);
  336. }
  337.  
  338.  
  339. printerrmsg (filename)
  340. char   *filename;
  341. {
  342.     fprintf (stderr, "Can not open %s\n", filename);
  343.     exit (1);
  344. }
  345.  
  346.  
  347. print_line (line, numbars, test)
  348. char   *line;
  349. int     numbars, test;
  350. {
  351.     char    fl = 'p';
  352.     int     barchar = 0,
  353.         counter = 0,
  354.             i,
  355.             length_of_line = strlen (line),
  356.             k = 0;
  357.  
  358.     break_line_up (numbars, line, test);
  359.     while (counter <= length_of_line - 1) {
  360.     k++;
  361.     if (k != 1) {
  362.         fputc ('\n', outfile);
  363.         printbars (numbars, barchar, fl);
  364.         if (test == TRUE)
  365.         for (i = 1; i <= INDENT; i++)
  366.             fputc (' ', outfile);
  367.             else
  368.             for (i = 1; i <= (indwidth + INDENT); i++)
  369.                 fputc (' ', outfile);
  370.         counter++;
  371.     }
  372.     while ((line[counter] != '\0') && (counter <= length_of_line - 1))
  373.         fputc (line[counter++], outfile);
  374.     }
  375. }
  376.  
  377. break_line_up (numbars, line, test)
  378. int     numbars,
  379.     test;
  380. char   *line;
  381.  
  382. {
  383.     int     k = 1,
  384.             out_line_length,
  385.             spaces_used,
  386.             pointer,
  387.             length_of_str = strlen (line),
  388.             counter;
  389.  
  390.     spaces_used = firstcol + numbars * indwidth - 1;
  391.     out_line_length = PRINTLNLGTH - spaces_used - RIGHT_MARGIN;
  392.     pointer = out_line_length;
  393.     if (test == TRUE)
  394.     out_line_length = out_line_length + 5;
  395.     if (out_line_length < length_of_str) {
  396.     while (pointer <= length_of_str - 3) {
  397.         counter = 0;
  398.         if (k == 2)
  399.                out_line_length -= INDENT;
  400.         while (!isspace (line[pointer - counter]))
  401.         counter++;
  402.         line[pointer - counter] = '\0';
  403.         pointer += (out_line_length - counter);
  404.         k++;
  405.     }
  406.     }
  407. }
  408.  
  409.  
  410. int getstring (char * line)
  411.  
  412. {
  413.     char    line2[LNLGTH];
  414.     int       place_of_alpha = 2;
  415.  
  416.     if (fgets (line, LNLGTH, infile) != NULL) {
  417.     place_of_alpha = find_alpha(line, place_of_alpha);
  418.     while (line[strlen (line) - place_of_alpha] == '\\') {
  419.         if (isspace(line[strlen (line) - (place_of_alpha + 1)])) {
  420.         place_of_alpha = find_alpha(line,
  421.             place_of_alpha + 1);
  422.         place_of_alpha--;
  423.         }
  424.         fgets (line2, LNLGTH, infile);
  425.         line[strlen (line) - (place_of_alpha)] = ' ';
  426.         line[strlen (line) - (place_of_alpha - 1)] = '\0';
  427.         strcat (line, line2);
  428.         place_of_alpha = 2;
  429.         place_of_alpha = find_alpha(line,
  430.             place_of_alpha);
  431.     }
  432.     }
  433.     else
  434.     return (0);
  435. }
  436.  
  437. find_alpha (char * line, int counter)
  438. {
  439.     while (isspace (line[strlen (line) - counter]))
  440.     counter++;
  441.     return (counter);
  442. }
  443.  
  444.     
  445.     return self;
  446. }
  447.  
  448.  
  449. @end
  450.